package com.lz.football.module.playerCenter
{
	import com.common.stdlib.ArrayUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.PlayerCenterEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.playerCenter.PlayerCenterDataConstant;
	import com.liangzhong.model.playerCenter.PlayerCenterDataManager;
	import com.liangzhong.model.playerCenter.vo.BattlearrayVo;
	import com.liangzhong.model.playerCenter.vo.PlayerPlaceVo;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.playerCenter.ComboBox.ComboBox;
	import com.lz.football.module.playerCenter.item.PlayerCenterPlayerItem;
	
	import common.BaseView.BaseView;
	import common.BaseView.DisplayMouseEventManager;
	import common.base.GoodsUsePanel;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	
	import lz.controls.Alert;
	import lz.controls.nick.PagePanel;
	
	/**
	 * 阵容设置 
	 * @author Administrator
	 * 
	 */	
	public class BattlearrayView extends BaseView//Sprite implements IComponent
	{
		//		private var _skin:MovieClip;
//		private var _hscroll:HScroll;
		/**
		 *皮肤  
		 * guide 引用 
		 */		
		public static var SkinObj :DisplayObject;
		/**
		 *背景 guide引用 
		 */		
		public static var SkinBg :Sprite;
		/**
		 *关闭按钮 
		 */		
		public static var closeBtn :SimpleButton;
		/**
		 * 滚动条容器
		 */
		private var _target:Sprite;
		/**
		 * 球员item
		 */
		private var _itemArr:Array = [];
		/**
		 *球场 
		 */
		private var _ballpark:MovieClip;
		/**
		 球场宽 
		 */
		private var _ballWidth:int;
		/**
		 *球场高 
		 */
		private var _ballHeight:int;
		/**
		 * 
		 */
		private var _playerCenterManager:PlayerCenterDataManager;
		/**
		 *选中的球员 
		 */
		private var _selectItem:PlayerCenterPlayerItem;
		/**
		 *体力 
		 */
		private var powerBtn:SimpleButton;
		/**
		 *buff 
		 */
		private var buffBtn:SimpleButton;
		/**
		 * 体力进度条
		 */
		private var progressbar:MovieClip;
		
		/**
		 * 
		 */
//		private var _tabBtn:TabBtnMenuPanel;
		/**
		 *装备容器 
		 */
//		private var equipContain:MovieClip;
		/**
		 * 选择了装备  
		 */
//		private var _selectEquip:PlayerEquipItem;
		/**
		 *装备List 
		 */
//		private var _equipVec:Vector.<PlayerEquipItem>;
		
		/**
		 * 
		 */
		private var _goodusePanel:GoodsUsePanel;
		/**
		 *场上的球员List； 
		 */
		private var _playerList:Array;
		/**
		 *保存按钮 
		 */
		public static var saveBtn:SimpleButton;
		
		/*下拉列表*/
		private var _comBoBox:ComboBox;
		/**
		 *列表容器 
		 */
		private var listContain:MovieClip;
		/**
		 *替补球员 
		 */
		private var substitutionList:Array;
		/**
		 * 
		 */
		private var _page:PagePanel;
		/**
		 *页容器 
		 */
		private var page:MovieClip;
		
		/**
		 *阵容上的球员 是否有改变 有为true否则没有，没有则不需要保存
		 */
		private var _ischangePlace:Boolean;
		public function BattlearrayView()
		{
			super();
		}
		
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.playerCenter.battleView");
			this.addChild(symbolSkin);
			_ballpark = symbolSkin.ballContain;
			_ballWidth = symbolSkin.ballpark.width;
			_ballHeight = symbolSkin.ballpark.height;
			saveBtn = symbolSkin.saveBtn;
			_windowBg = symbolSkin.battleBg;
			isDrag = true;
			isCloseBtn = true;
			moveClose(553,28);
			_viewWidth = symbolSkin.width;
			_viewHeight = symbolSkin.height;
			onResizeHandler();
			_playerCenterManager = AppData.getInstance().playerCenterDataManager;
			
			//			initScroll();
			saveBtn = symbolSkin.saveBtn;
			listContain = symbolSkin.listContain;
			page = symbolSkin.page;
			initPage();
			_comBoBox = new ComboBox();
			_comBoBox.initUI(symbolSkin.comboBox);
			_comBoBox.setData([{label:"4-3-3",value:1},{label:"3-4-3",value:2},{label:"4-4-2",value:3},{label:"4-5-1",value:4},
				{label:"5-3-2",value:5},{label:"5-4-1",value:6}],_playerCenterManager.firstBattlearrayVo.ntype);
			
//			oncomBoBoxHandler();
			
			
			_playerList = _playerCenterManager.firstBattlearrayVo.battlearrayList;
			
//			upDataPlayerPlace();
			addEvtListener();
			saveBtnfilters = false;
			//@lake 2013-11-16
			SkinObj = symbolSkin;
			SkinBg = _windowBg;
			closeBtn = _closeBtn;
		}
		

		/**
		 *初始化页 
		 * 
		 */
		private function initPage():void
		{
			_page = new PagePanel();
			_page.initUI("com.lz.commonUI.turnPage_white");
			_page.callBack = turnPage;
			page.addChild(_page);
		}
		

		/**
		 *更新球员位置 
		 * 
		 */
		public function upDataPlayerPlace():void
		{
			if(_target == null)_target = new Sprite();
			resetItem();
			if(substitutionList == null)substitutionList = [];
			substitutionList.splice(0,substitutionList.length);
			var arr:Array = _playerCenterManager.playerList;
			var len:int = arr.length;
			var item:PlayerCenterPlayerItem;
			var vo:PlayerPlaceVo;
			var batVo:BattlearrayVo;
			for(var i:int =0 ;i < len;i++)
			{
				vo = getPlaceVo(arr[i].playerid);
//				substitutionList.push(arr[i]);
//				continue;
				if(vo != null)
				{
					item = getItem();
					item.data = arr[i];
					item.selectFunction = selectItem;
					item.callBack = ballUpToDown;
					item.x = vo.flasx - 25//- (item.width >> 1);
					item.y = vo.flasy -33 //- (item.height>> 1);
					_ballpark.addChild(item);
				}
				else
				{
					substitutionList.push(arr[i]);
				}
				if((arr[i]as PlayerVo).self == 1)
				{
					selectItem(item);
				}
			}
			
			_page.min = 1;
			_page.max = Math.ceil(substitutionList.length / 15);
			if(_page.max <=0)
				_page.max = 1;
			turnPage();
		}
		/**
		 *换页 
		 * @param $type
		 * 
		 */
		private function turnPage($type:String = ""):void
		{
			while(listContain.numChildren)
			{
				item = listContain.removeChildAt(0) as PlayerCenterPlayerItem;
				returnItem(item);
			}	
			var arr:Array = ArrayUtil.getPageSizeDatas(_page.min,15,substitutionList);
			var len:int = arr.length;
			var item:PlayerCenterPlayerItem;
			for(var i:int = 0;i < len;i++)
			{
				item = getItem();
				item.data = arr[i];
				item.selectFunction = selectItem;
				item.callBack = ballDownToUp;
				item.x = (item.width + 2) * (listContain.numChildren %3);
				item.y = (item.height + 2) *int(listContain.numChildren /3);
				listContain.addChild(item);
			}
		}
		/**
		 *获取场上的球员 
		 * 
		 */
		private function getPlaceVo($id:int):PlayerPlaceVo
		{
			for each(var vo:PlayerPlaceVo in _playerList)
			{
				if(vo.playerid == $id)
					return vo;
			}
			return null;
			
		}
		/**
		 *选中球员 
		 * @param $item
		 * 
		 */
		private function selectItem($item:PlayerCenterPlayerItem):void
		{
			if(_selectItem != null)
			{
				_selectItem.select = false;
			}
			_selectItem = $item;
			if(_selectItem == null)
			{
				return ;
			}
			_selectItem.select = true;
		}
		/**
		 *场上到场下 或者 在场上拖动
		 * @param $upItem拖动的item
		 * @param $downItem替换的item
		 */
		private function ballUpToDown($dragItem:PlayerCenterPlayerItem,$replaceItem:PlayerCenterPlayerItem):void
		{
			//先判断拖动是否为GK守门员
			var dragplayerVo:PlayerVo = $dragItem.data as PlayerVo;
			
			var obj:Object;
			var len:int;
			var i:int;
			if(dragplayerVo.place == PlayerCenterDataConstant.GK_PLACE && isGkPlace($dragItem))//场上拖的是守门员
			{
				if($replaceItem == null)//替换的为空，则只拖动守门员，守门员不可以拖动
				{
					Alert.showErrorTip("守门员不可以拖动");
					return ;
				}
				if(($replaceItem.data as PlayerVo).place != PlayerCenterDataConstant.GK_PLACE)//替换的不是守门员，守门员只可使用守门员替换
				{
					Alert.showErrorTip("守门员只可使用守门员替换");
					return;
				}
				if($dragItem == $replaceItem)return;
				obj = $dragItem.data;
				$dragItem.data = $replaceItem.data;
				$replaceItem.data = obj;
				saveBtnfilters = true;
				len = substitutionList.length;
				len = substitutionList.length;
				for(i = 0;i < len;i++)
				{
					if(rePlacePlayerVo == null)break;
					if(substitutionList[i].playerid == rePlacePlayerVo.playerid )
					{
						substitutionList[i] = dragplayerVo;
						break;
					}
					
				}
				return;
			}
			var rePlacePlayerVo:PlayerVo
			if($replaceItem != null)
			{
				rePlacePlayerVo = $replaceItem.data as PlayerVo;
				if(isGkPlace($replaceItem) && dragplayerVo.place != PlayerCenterDataConstant.GK_PLACE)
				{
					Alert.showErrorTip("守门员只可使用守门员替换");
					return;
				}
			}
			
			
			if($replaceItem == null || $dragItem == $replaceItem)//拖动场上的球员 
			{
				dragPlayer($dragItem);
				saveBtnfilters = true;
				return;
			}
			
			obj = $dragItem.data;
			$dragItem.data = $replaceItem.data;
			$replaceItem.data = obj;
			saveBtnfilters = true;
			
			len = substitutionList.length;
			for(i = 0;i < len;i++)
			{
				if(substitutionList[i].playerid == rePlacePlayerVo.playerid )
				{
					substitutionList[i] = dragplayerVo;
					break;
				}
				
			}
		}
		
		/**
		 * 场下到场上 
		 * @param $upItem拖动的item
		 * @param $downItem替换的item
		 * 
		 */
		private function ballDownToUp($dragItem:PlayerCenterPlayerItem,$replaceItem:PlayerCenterPlayerItem):void
		{
			if($replaceItem == null)return;
			if($replaceItem.parent == $dragItem.parent)return;
			var rePlacePlayerVo:PlayerVo = $replaceItem.data as PlayerVo;
			var dragPlayerVo:PlayerVo = $dragItem.data as PlayerVo;
			var obj:Object
			if(rePlacePlayerVo.place == PlayerCenterDataConstant.GK_PLACE)//判断场被替换是否为守门员，如果是需要判断拖动的是否为守门员
			{
				if(isGkPlace($replaceItem) && dragPlayerVo.place != PlayerCenterDataConstant.GK_PLACE)
				{
					Alert.showErrorTip("守门员只可使用守门员替换");
					return;
				}
			}
			
			
			obj = $dragItem.data;
			$dragItem.data = $replaceItem.data;
			$replaceItem.data = obj;
			var len:int = _playerList.length;
//			substitutionList
			var i:int;
			for(i = 0;i < len;i++)
			{
				if(_playerList[i].playerid == rePlacePlayerVo.playerid)
				{
					saveBtnfilters = true;
					break;
				}
			}
			len = substitutionList.length;
			for(i = 0;i < len;i++)
			{
				if(substitutionList[i].playerid == dragPlayerVo.playerid )
				{
					substitutionList[i] = rePlacePlayerVo;
					break;
				}
				
			}
		}
		/**
		 *在球场中拖动球员  
		 * 412  ,251 原始球场坐标
		 */
		private function dragPlayer($dragItem:PlayerCenterPlayerItem):void
		{
			//			if(pointBoolean($oldItem) && $dragItem.playerVo.place == "GK")
			//			{
			//				Alert.showErrorTip("守门员不可拖动");
			//				return;
			//			}
			var point:Point = _ballpark.globalToLocal(new Point(this.stage.mouseX,this.stage.mouseY));
			//			trace("poine.x:"+ point.x + "point .y :"+ point.y);
			
			var tempx:int = point.x - ($dragItem.width >>1);
			
			if(tempx >= 130 && (tempx  <= 191)  &&
				(point.y >= 343))
			{
				Alert.showErrorTip("守门员位置不可以放其他球员");
				return;//控制守门员的位置（守门员位置不可以放其他球员）
			}
			$dragItem.x = point.x - ($dragItem.width >>1);
			if($dragItem.x < 4)
				$dragItem.x = 4;
			if(point.x  + ($dragItem.width>>1) >= _ballWidth -4)
				$dragItem.x = _ballWidth - $dragItem.width -4;
			
			
			$dragItem.y = point.y - ($dragItem.height>>1 );
			if($dragItem.y <4)
				$dragItem.y = 4;
			if(point.y +($dragItem.height >>1) > _ballHeight - 4)
				$dragItem.y = _ballHeight - $dragItem.height - 4;
			//			if($dragItem.y <0)
			//				$dragItem.y = 0;
			$dragItem.parent.addChild($dragItem);
			
		}
		/**
		 *判断是否为守门员的位置 
		 * @param $item
		 * 
		 */
		private function isGkPlace($item:PlayerCenterPlayerItem):Boolean
		{
			if(($item.x >= 142 && $item.x <= 190)&&$item.y >= 344)
			{
				return true;//控制守门员的位置（守门员位置不可以放其他球员）
			}
			return false;
		}
		/**
		 * 获取item
		 * 
		 */
		private function getItem():PlayerCenterPlayerItem
		{
			if(_itemArr.length > 0)
				return _itemArr.pop();
			var item:PlayerCenterPlayerItem;
			item = new PlayerCenterPlayerItem();
			item.initUI();
			_itemArr.push(item);
			return getItem();
		}
		/**
		 * 还原球员item
		 * 
		 */
		private function returnItem($item:PlayerCenterPlayerItem):void
		{
			_itemArr.push($item);
		}
		/**
		 * 重置球员ITem 
		 * 
		 */
		private function resetItem():void
		{
			var item:PlayerCenterPlayerItem;
			while(_ballpark.numChildren > 0)
			{
				item = _ballpark.removeChildAt(0)as PlayerCenterPlayerItem;
				returnItem(item);
			}
			while(listContain.numChildren)
			{
				item = listContain.removeChildAt(0) as PlayerCenterPlayerItem;
				returnItem(item);
			}
		}
		override public function removeEvtListener():void
		{
			
			super.removeEvtListener();
			saveBtn.removeEventListener(MouseEvent.CLICK,onSaveHandler);
			_comBoBox.removeEventListener(Event.SELECT,oncomBoBoxHandler);
			DisplayMouseEventManager.instance.removeTipsDisplay(saveBtn);
			
			
			
		}
		
		override public function destroyView():void
		{
			removeEvtListener();
			if(_comBoBox != null)_comBoBox.destroyView();
			_comBoBox = null;
			var i:PlayerCenterPlayerItem;
			while(_itemArr.length)
			{
				i = _itemArr.pop();
				i.destroyView();
				i = null;
			}
			_itemArr = null;
			_page.destroyView();
			_page = null;
			var item:PlayerCenterPlayerItem;
			while(listContain.numChildren)
			{
				item = listContain.removeChildAt(0) as PlayerCenterPlayerItem;
				item.destroyView();
				item = null;
			}	
			while(_ballpark.numChildren )
			{
				item = _ballpark.removeChildAt(0)as PlayerCenterPlayerItem;
				item.destroyView();
				item = null;
			}
			super.destroyView();
			SkinObj = null;
			saveBtn = null;
			SkinBg = null;
			closeBtn = null;
		}
		/**
		 * 保存按钮
		 * 
		 */
		private function set saveBtnfilters($value:Boolean):void
		{
//			if($value)
//			{
//				saveBtn.filters = null;
//				saveBtn.mouseEnabled = true;
//			}else
//			{
//				var arr:Array = [new ColorMatrixFilter([0.5,0.5,0.5,0,0,
//					0.5,0.5,0.5,0,0,
//					0.5,0.5,0.5,0,0,
//					0,0,0,1,0,])];
//				saveBtn.filters = arr;
//				saveBtn.mouseEnabled = false;
//			}
			_ischangePlace = $value;
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REMOVE_BATTLE_VIEW,null,true));
			super.onCloseHandler(event);
		}


		/**
		 *阵容改变 
		 * @param $obj
		 * 
		 */
		public function save_battlearray($obj:Object):void
		{
			saveBtn.addEventListener(MouseEvent.CLICK,onSaveHandler);
			saveBtnfilters =false;
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			saveBtn.addEventListener(MouseEvent.CLICK,onSaveHandler);
			_comBoBox.addEventListener(Event.SELECT,oncomBoBoxHandler);
			DisplayMouseEventManager.instance.addTipsDisplay(saveBtn,"鼠标拖动球员进行位置调整！");
		}
		
		protected function onRemoveThisHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			if(_goodusePanel != null && _goodusePanel.parent)
				_goodusePanel.parent.removeChild(_goodusePanel);
			if(saveBtn != null)
			{
				saveBtnfilters = false;
			}
		}
		
		/**
		 *选择了阵型  
		 * @param event
		 * 
		 */
		public function oncomBoBoxHandler(event:Event = null):void
		{
			_playerList = _playerCenterManager.getdefaultBattlearray(_comBoBox.data.value);
			upDataPlayerPlace();
			saveBtnfilters = true;
			
		}
		
		/**
		 *保存阵型  
		 * @param event
		 * 
		 */
		protected function onSaveHandler(event:MouseEvent):void
		{
			if(!_ischangePlace)
			{
				Alert.showErrorTip("阵容没有发生变化!");
				return;
			}
			
			//			var formation:int = _tabBtn.selectType;//阵容
						var ntype:int = _comBoBox.data.value;//阵型类型
			var i:int = 0;
			var item:PlayerCenterPlayerItem;
			var arr:Array = [];
			var obj:Object;
			while(_ballpark.numChildren > i)
			{
				obj= {};
				item = _ballpark.getChildAt(i) as PlayerCenterPlayerItem;
//				if((item.data as PlayerVo).place == 1)
//				{
//					obj.x = int(item.x)// + (item.width >> 1);
//					obj.y = int(item.y)  //+ (item.height >>1);
//				}else
//				{
//					obj.x = int(item.x) + 25// + (item.width >> 1);
//					obj.y = int(item.y)  + 33//+ (item.height >>1);
//				}
				obj.x = int(item.x) + 25// + (item.width >> 1);
				obj.y = int(item.y)  + 33//+ (item.height >>1);
//				trace("playerId:"+ (item.data as PlayerVo).playerid +(item.data as PlayerVo).place_String + "X:" + obj.x + "Y:" + obj.y );
				
//				trace((item.data as PlayerVo).playerid + "-->" + (item.data as PlayerVo).place_String + "["+ obj.x + "," + obj.y +"]");
				obj.id = (item.data as PlayerVo).playerid;
				arr.push(obj);
				i++;
			}
			saveBtn.removeEventListener(MouseEvent.CLICK,onSaveHandler);
			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.SAVE_BATTLEARRAY,{formation:1,ntype:ntype,obj:arr}));
			
		}
		/**
		 *阵容类型显示 
		 * @param $value
		 * @return 
		 * 
		 */		
		private function selectbattleType($value:int):Object
		{
			switch($value)
			{
				case 1:
					return {label:"4-3-3",value:1};
				case 2:
					return {label:"3-4-3",value:2};
				case 3:
					return {label:"4-4-2",value:3};
				case 4:
					return {label:"4-5-1",value:4}
				case 5:
					return {label:"5-3-2",value:5}
				case 6:
					return {label:"5-4-1",value:6};
			}
			return {};
		}
		/**
		 * 显示使用的阵容
		 * 
		 */
		public function showUseBattle():void
		{
			_comBoBox.defaultSelect(selectbattleType(_playerCenterManager.firstBattlearrayVo.ntype));
			_playerList = _playerCenterManager.firstBattlearrayVo.battlearrayList;
			upDataPlayerPlace();
			//saveBtnfilters = true;
			
		}
		/**
		 *删除一个球员 
		 * @param $id
		 * 
		 */
		public function removePlayer($id:int):void
		{
			var len:int = substitutionList.length;
			for(var i:int = 0;i < len;i++)
			{
				if(substitutionList[i].playerid == $id)
				{
					substitutionList.splice(i,1);
					break;
				}
			}
			_page.max = Math.ceil(substitutionList.length / 15);
			if(_page.max <=0)
				_page.max = 1;
			if(_page.min > _page.max)_page.min = _page.max;
			turnPage();
		}
		/**
		 *增加一个球员 
		 * @param $id
		 * 
		 */
		public function addPlayer($id:int):void
		{
			var vo:PlayerVo = _playerCenterManager.getplayerVoById($id);
			substitutionList.push(vo);
			_page.max = Math.ceil(substitutionList.length / 15);
			if(_page.max <=0)
				_page.max = 1;
			if(_page.min > _page.max)_page.min = _page.max;
			turnPage();
		}
		
		
//		protected function onTabHandler(event:Event = null):void
//		{
			//			switch(_tabBtn.selectType)
			//			{
			//				case TabBtnConst.ONE_CONST:
			//					_playerList = _playerCenterManager.firstBattlearrayVo.battlearrayList;
			//					//					_playerList = _playerCenterManager.getdefaultBattlearray(1);
			//					_comBoBox.defaultSelect({value:_playerCenterManager.firstBattlearrayVo.ntype});
			//					break;
			//				case TabBtnConst.TWO_CONST:
			//					_playerList = _playerCenterManager.secondBattlearrayVo.battlearrayList;
			//					//					_playerList = _playerCenterManager.getdefaultBattlearray(2);
			//					_comBoBox.defaultSelect({value:_playerCenterManager.secondBattlearrayVo.ntype});
			//					break;
			//			}
			
			
			//			_playerList = _playerCenterManager.firstBattlearrayVo.battlearrayList;
			
//			_comBoBox.defaultSelect({value:_playerCenterManager.firstBattlearrayVo.ntype});
//			_playerList = _playerCenterManager.getdefaultBattlearray(_comBoBox.data.value);
//			upDataPlayerPlace();
//			saveBtnfilters = false;
//		}
//		/**
//		 * 
//		 * 
//		 */
//		public function setUpdataInfo():void
//		{
//			_tabBtn.setSelectStatus(TabBtnConst.ONE_CONST);
//			onTabHandler();
//		}
		
//		/**
//		 * 改变状态 
//		 * @param event
//		 * 
//		 */
//		protected function onBuffHandler(event:MouseEvent):void
//		{
//			if(_selectItem==null)return;
//			if(_goodusePanel == null)_goodusePanel = GoodsUsePanel.inistance;
//			_goodusePanel.initPlace();
//			//			_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.MEDICALCARD);
//			_goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.MEDICALCARD);
//			
//			_goodusePanel.callBack  = useBuffGoods;
////			onRemoveGoodsUsePanelHandler();
//			
//		}
//		/**
////		 *使用buff物品 
////		 * @param $goodsVo
////		 * 
////		 */
//		private function useBuffGoods($goodsVo:GoodsVo):void
//		{
//			if(_selectItem==null)return;
//			var vo:PlayerVo = _selectItem.data as PlayerVo
//			if(vo.status ==1)
//			{
//				Alert.showErrorTip("球员状态良好，不需要回复");
//				return;
//			}
//			//			var cellid:int ;
//			//			if($goodsVo == null)
//			//				cellid = 0;
//			//			else
//			//				cellid = $goodsVo.pid;
//			//			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_BUFF,{type:1,id:vo.playerid,cellId:cellid}));
//			
//			
//			
//			
//			if($goodsVo == null)
//			{
//				Alert.show("治疗该受伤球员需要花费25000欧元，确定吗？","",Alert.NO,GlobalDef.AlertContainer,useBuff);
//				function useBuff($type:int):void
//				{
//					if($type == Alert.YES)
//					{
//						AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_BUFF,{type:1,id:vo.playerid,cellId:0}));
//					}
//				}
//				return;
//			}
//			var cellid:int ;
//			
//			cellid = $goodsVo.pid;
//			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_BUFF,{type:1,id:vo.playerid,cellId:cellid}));
//		}
		
//		/**
//		 *增加体力 
//		 * @param event
//		 * 
//		 */
//		protected function onPowerHandler(event:MouseEvent):void
//		{
//			if(_goodusePanel == null)_goodusePanel = GoodsUsePanel.inistance;
//			_goodusePanel.initPlace();
//			//			_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.PHYSICAL);
//			_goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.PHYSICAL);
//			
//			_goodusePanel.callBack = usePowerGoods;
//			onRemoveGoodsUsePanelHandler();
//		}
//		/**
//		 *使用体力物品增加体力 
//		 * @param $goodsVo
//		 * 
//		 */
//		private function usePowerGoods($goodsVo:GoodsVo):void
//		{
//			if(_selectItem==null)return;
//			var vo:PlayerVo = _selectItem.data as PlayerVo
//			if(vo.physical == vo.maxphysical)
//			{
//				Alert.showErrorTip("体力充沛，不需要回复");
//				return;
//			}
//			//			var cellid:int ;
//			//			if($goodsVo == null)
//			//				cellid = 0;
//			//			else
//			//				cellid = $goodsVo.pid;
//			//			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,{type:1,id:vo.playerid,cellId:cellid}));
//			
//			
//			if($goodsVo == null)
//			{
//				Alert.show("治疗该受伤球员需要花费25000欧元，确定吗？","",Alert.NO,GlobalDef.AlertContainer,useBuff);
//				function useBuff($type:int):void
//				{
//					if($type == Alert.YES)
//					{
//						AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,
//							{type:1,id:vo.playerid,cellId:0}));
//					}
//				}
//				return;
//			}
//			var cellid:int ;
//			cellid = $goodsVo.pid;
//			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(PlayerCenterEvent.REPLY_PLAYER_POWER,
//				{type:1,id:vo.playerid,cellId:cellid}));
//		}
		//		/**
		//		 *显示装备信息 
		//		 * 
		//		 */
		//		private function showEquipInfo(star:PlayerVo):void
		//		{
		//			if(star.attr1 >0)
		//			{
		//				_equipVec[0].data = {goodsId:star.attr1,type:GoodsType.ATTRIBUTE,lock:star.attr1lock};
		//			}else
		//			{
		//				_equipVec[0].reset();
		//			}
		//			if(star.attr2 > 0)
		//			{
		//				_equipVec[1].data = {goodsId:star.attr2,type:GoodsType.ATTRIBUTE,lock:star.attr2lock};
		//			}else
		//			{
		//				_equipVec[1].reset();
		//			}
		//			if(star.equip1 > 0)
		//			{
		//				_equipVec[2].data = {goodsId:star.equip1,type:GoodsType.FOOTWEAR,lock:star.equip1lock};//GoodsType.FOOTWEAR
		//			}else
		//			{
		//				_equipVec[2].reset();
		//			}
		//			
		//			if(star.equip2 > 0)
		//			{
		//				_equipVec[3].data = {goodsId:star.equip2,type:GoodsType.FOOTWEAR,lock:star.equip2lock};
		//			}else
		//			{
		//				_equipVec[3].reset();
		//			}
		//			if(_selectEquip != null)
		//				_selectEquip.select = true;
		//		}
		//		/**
		//		 *更新装备信息 
		//		 * 
		//		 */
		//		public function updataEquipInfo($obj:Object):void
		//		{
		//			if((_selectItem.data as PlayerVo).playerid != $obj.playerId)return;
		//			showEquipInfo(_selectItem.data as PlayerVo);
		//更新物品使用面板
		//			if(_goodusePanel.parent)
		//			{
		//				if(int(_selectEquip.type /2) == 1)//FOOTWEAR鞋袜卡
		//					 _goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR)//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.FOOTWEAR);
		//				else//属性卡
		//					_goodusePanel.setShowGoodsType(GoodsType.ATTRIBUTE)//_goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR)AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.ATTRIBUTE);
		//			}
		
		//		}
//		/**
//		 //		 *体力和状态改变 
//		 //		 * @param $playerId
//		 //		 * 
//		 //		 */
		//		public function changePowerAndBuff($obj:Object):void
		//		{
		//			if(!this.parent)return;
		//			if(_selectItem == null)return;
		//			if($obj.id == (_selectItem.data as PlayerVo).playerid)
		//			{
		//				_selectItem.updataBuff();
		//				if(_goodusePanel.parent)_goodusePanel.parent.removeChild(_goodusePanel);
		//				if(!GoodsUsePanel.inistance.parent)return;
		//				if($obj.type == 1)
		//				{
		//					 _goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.MEDICALCARD)//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.MEDICALCARD);
		//					_goodusePanel.callBack = useBuffGoods;
		//				}else if($obj.type == 2)
		//				{
		////					_goodusePanel.goodsList = AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.OTHER,OtherGoodType.PHYSICAL);
		//					_goodusePanel.setShowGoodsType(GoodsType.OTHER,OtherGoodType.PHYSICAL)
		//					_goodusePanel.callBack = usePowerGoods;
		//				}
		//			}
		//			
		//			
		//			
		//		}
		
		//		/**
		//		 *初始化装备  
		//		 * 
		//		 */
		//		private function initEquipItem():void
		//		{
		//			_equipVec = new Vector.<PlayerEquipItem>();
		//			var item:PlayerEquipItem;
		//			for(var i:int = 0;i < 4;i++)
		//			{
		//				item = new PlayerEquipItem();
		//				item.initUI("com.lz.commonUI.ItemFrame");
		//				item.x = (item.width + 5)*(i % 2)
		//				item.y = (item.width + 2) * int (i/2);
		//				item.type = i;
		//				item.addLock();
		//				item.callBack = selectEquip;
		//				equipContain.addChild(item);
		//				_equipVec.push(item);
		//			}
		//		}
		
		//		/**
		//		 *选择了装备  
		//		 * 
		//		 */
		//		private function selectEquip($item:PlayerEquipItem,$isDouble:Boolean):void
		//		{
		//			if(_selectItem == null)
		//			{
		//				Alert.showErrorTip("选择球员");
		//				return ;
		//			}
		//			if(_selectEquip != null)
		//			{
		//				if(int(_selectEquip.type /2)!= int($item.type/2))
		//				{
		//					Alert.showErrorTip("选择的类型不同");
		//					return;
		//				}
		//			}
		//			_goodusePanel = GoodsUsePanel.inistance
		//			
		//			
		//			if(_selectEquip == null)
		//			{
		//				if(_selectEquip!= null)_selectEquip.select = false;
		//				_selectEquip = $item;
		//				_selectEquip.select = true;
		//				_goodusePanel.initPlace();
		//				if(int(_selectEquip.type /2) == 1)//FOOTWEAR鞋袜卡
		//					_goodusePanel.setShowGoodsType(GoodsType.FOOTWEAR);//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.FOOTWEAR);
		//				else//属性卡
		//					_goodusePanel.setShowGoodsType(GoodsType.ATTRIBUTE)//AppData.getInstance().bagDataManager.getGoodsListByTwoTypes(GoodsType.ATTRIBUTE);
		//				_goodusePanel.callBack = useGoods;
		//				_goodusePanel.addEventListener(Event.REMOVED_FROM_STAGE,onRemoveGoodsUsePanelHandler);
		//				return;
		//			}
		//			
		//			if(_selectEquip!= null)_selectEquip.select = false;
		//			_selectEquip = $item;
		//			_selectEquip.select = true;
		//			if($isDouble &&　$item.data != null)//双击了装备，则换下装备
		//			{
		//				var playerId:int = (_selectItem.data as PlayerVo).playerid;
		//				var cellId:int = 0;
		//				var posid:int = (_selectEquip.type % 2) == 0 ? 1:2;//位置
		//				var ntype:int = int(_selectEquip.type / 2) == 0? 3:2;//道具类型：3为属性卡 2为鞋袜卡
		//				
		//				AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(
		//					PlayerCenterEvent.REPLACE_EQUIP,{playerId:playerId,cellId:cellId,posid:posid,ntype:ntype}));
		//			}
		//		}
		
		
		//		/**
		//		 *使用物品（更换装备） 
		//		 * 
		//		 */
		//		private function useGoods($goods:GoodsVo):void
		//		{
		//			if($goods == null)return;
		//			if(_selectItem.data == null || _selectItem == null)
		//			{
		//				Alert.showErrorTip("选择球员");
		//				return
		//			}
		//			if(_selectEquip == null)
		//			{
		//				Alert.showErrorTip("选择装备类型");
		//				return;
		//			}
		//			var playerId:int = (_selectItem.data as PlayerVo).playerid;
		//			var cellId:int = $goods.pid;
		//			var posid:int = (_selectEquip.type % 2) == 0 ? 1:2;//位置
		//			var ntype:int = int(_selectEquip.type / 2) == 0? 3:2;//道具类型：3为属性卡 2为鞋袜卡
		//			AppEventDispatcher.getInstance().dispatchEvent(new PlayerCenterEvent(
		//				PlayerCenterEvent.REPLACE_EQUIP,{playerId:playerId,cellId:cellId,posid:posid,ntype:ntype}));
		//		}
		//		/**
		//		 * 物品使用面板移除 
		//		 * @param event
		//		 * 
		//		 */
		//		protected function onRemoveGoodsUsePanelHandler(event:Event = null):void
		//		{
		// TODO Auto-generated method stub
		//			if(_selectEquip != null)_selectEquip.select = false;
		//			_selectEquip = null;
		//		}
		//		/**
		//		 *初始化流动条 
		//		 * 
		//		 */
		//		private function initScroll():void
		//		{
		//			if(_hscroll != null)return;
		//			
		//			_hscroll = new HScroll();
		//			_hscroll.setBtn(symbolSkin._leftBtn,symbolSkin._rightBtn);
		//			_hscroll.defaultContain = symbolSkin._default;
		//			_hscroll.setWidth(348);
		//			_hscroll.defaultTarget = _target;
		//			_hscroll.speed = 58;
		//			_hscroll.delayedTime = 0.3;
		//			_hscroll.upData();
		//		}
	}
}